/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package getrootbahasa;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import weka.classifiers.Evaluation;
import weka.classifiers.bayes.NaiveBayes;
import weka.classifiers.misc.SerializedClassifier;
import weka.core.Instances;
import weka.core.converters.ArffLoader;

/**
 *
 * @author WaOnEmperoR
 */
public class MainV6_Evaluate {

    public static void main(String[] args) throws Exception{

        ArffLoader testLoader = new ArffLoader();

        try {
            testLoader.setSource(new File("test_TFIDF1.arff"));//Source file testing
            Instances test = testLoader.getDataSet();
            test.setClassIndex(test.numAttributes() - 1);

            SerializedClassifier nb = LoadModel("TFIDF_kfold10_baru.model");

            for (int i = 0; i < test.numInstances(); i++) {
                double pred = nb.classifyInstance(test.instance(i));
                System.out.println("Dokumen ke : " + (i+1) + " Prediksi = " + test.classAttribute().value((int) pred));
            }
        } catch (IOException ex) {
            Logger.getLogger(MainV6_Evaluate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


    public static SerializedClassifier LoadModel(String pathToModel){
        SerializedClassifier classifier = new SerializedClassifier();
        classifier.setModelFile(new File(pathToModel));

        return classifier;
    }
}
